package com.risenb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.risenb.bean.Module;
import com.risenb.bean.Page;
import com.risenb.dao.ManagerMapper;
import com.risenb.dao.ModuleMapper;
import com.risenb.service.ModuleService;
@Service
public class ModuleServiceImpl implements ModuleService {
	
	@Autowired
	ModuleMapper moduleMapper;
	
	@Autowired
	ManagerMapper managerMapper;
	
	@Override
	public int removeModuleById(Integer id) {
		return moduleMapper.removeModuleById(id);
	}

	@Override
	public int createModule(Module record) {
		return moduleMapper.createModule(record);
	}

	@Override
	public Module queryModuleById(Integer id) {
		Module module = moduleMapper.queryModuleById(id);
		if(module!=null)
		module.setParentM(moduleMapper.queryModuleById(module.getParentid()));
		return module;
	}

	@Override
	public int modifyModuleById(Module record) {
		return moduleMapper.modifyModuleById(record);
	}

	@Override
	public List<Module> queryModuleByGroupId(Integer groupId) {
		return moduleMapper.queryModuleByGroupId(groupId);
	}

	@Override
	public List<Module> queryAllModuleByChirld(Integer id) {
		return moduleMapper.queryAllModuleByChirld(id);
	}

	@Override
	public List<Module> queryAllModuleByParent(Integer id) {
		return moduleMapper.queryAllModuleByParent(id);
	}

	@Override
	public List<Module> queryAll() {
		return moduleMapper.queryAll();
	}

	@Override
	public List<Module> queryModuleByPage(Page<Module> module) {
		List<Module> ms = moduleMapper.queryModuleByPage(module);
		for (int i = 0; i < ms.size(); i++) {
			ms.get(i).setOperatorM(managerMapper.queryManagerById(ms.get(i).getOperator()));
			ms.get(i).setParentM(moduleMapper.queryModuleById(ms.get(i).getParentid()));
		}
		return ms;
	}

	@Override
	public int removeModuleByIds(List<String> ids) {
		return moduleMapper.removeModuleByIds(ids);
	}

}
